/*
 * new Promise((resolve) => {
 *   const obj = {
 *     then(resolve, reject) {
 *       reject('reject message')
 *     },
 *   }
 *   resolve(obj)
 * }).then(
 *   (res) => {
 *     console.log('res=>' + res)
 *   },
 *   (err) => {
 *     console.log('err=>' + err)
 *   },
 * )
 */

/*
 * new Promise((resolve, reject) => {
 *   resolve(new Promise((resolve, reject) => {
 *     reject('resolve message')
 *   }))
 * }).then(
 *   (res) => {
 *     console.log('res=>' + res)
 *   },
 */

/*
 * ).catch((err) => {
 *   console.log('err=>' + err)
 * })
 */
/*
 * new Promise((resolve) => {
 *   resolve('fddm')
 * }).then((res) => {
 *   console.log(res)
 *   return '1'
 * }).then((res) => {
 *   console.log(res)
 *   return 2
 * }).then((res) => {
 *   console.log(res)
 * })
 */
/*
 * 对象方法之catch()
 * const promise = new Promise((resolve, reject) => {
 *   reject('错误方法')
 * })
 * promise.then(() => new Promise((resolve, reject) => {
 *   reject('错误方法二')
 *   throw new Error('错误方法三')
 * },
 * )).catch((err) => {
 *   console.log(err)
 * })
 */
/*
 *catch的返回值还是一个promise
 * new Promise((resolve, reject) => {
 *   reject('错误信息')
 * }).catch((err) => {
 *   console.log('err', err)
 *   return 'catch的返回值'
 * }).then((res) => {
 *   console.log('res', res)
 * })
 */
/*
 * const promie = new Promise((resolve, reject) => {
 *   resolve({ name: 'fddm' })
 * })
 * // 相当于
 * const promise2 = Promise.resolve({ name: 'fddm' })
 */
/*
 *类方法 all() 当每一个promise的返回值都是resolve才会返回所有的值，出现一个reject就只会返回reject值
 * const p1 = new Promise((resolve) => {
 *   setTimeout(() => {
 *     resolve('111')
 *   }, 1000)
 * })
 * const p2 = new Promise((resolve) => {
 *   setTimeout(() => {
 *     resolve('222')
 *   }, 2000)
 * })
 * const p3 = new Promise((resolve,reject) => {
 *   setTimeout(() => {
 *     reject('333')
 *   }, 3000)
 * })
 * Promise.all([p1, p2, p3, { name: 'fddm' }]).then((res) => {
 *   console.log(res)
 * }).catch((err) => {
 *   console.log(err)
 * })
 */
/*
 *allSettled()
 * const p1 = new Promise((resolve) => {
 *   setTimeout(() => {
 *     resolve('111')
 *   }, 1000)
 * })
 * const p2 = new Promise((resolve) => {
 *   setTimeout(() => {
 *     resolve('222')
 *   }, 2000)
 * })
 * const p3 = new Promise((resolve, reject) => {
 *   setTimeout(() => {
 *     reject('333')
 *   }, 3000)
 * })
 * Promise.allSettled([p1, p2, p3, { name: 'fddm' }]).then((res) => {
 *   console.log(res)
 * })
 */
/*
 * 类方法  返回最快结果 不论是否是fulfilled
 * const p1 = new Promise((resolve, reject) => {
 *   setTimeout(() => {
 *     reject('111')
 *   }, 400)
 * })
 * const p2 = new Promise((resolve) => {
 *   setTimeout(() => {
 *     resolve('222')
 *   }, 200)
 * })
 * const p3 = new Promise((resolve) => {
 *   setTimeout(() => {
 *     resolve('333')
 *   }, 300)
 * })
 * Promise.race([p1, p2, p3]).then((res) => {
 *   console.log('res', res)
 * }, (err) => {
 *   console.log('err', err)
 * })
 */
const p1 = new Promise((resolve, reject) => {
  setTimeout(() => {
    reject('111')
  }, 100)
})
const p2 = new Promise((resolve) => {
  setTimeout(() => {
    resolve('222')
  }, 200)
})
const p3 = new Promise((resolve) => {
  setTimeout(() => {
    resolve('333')
  }, 300)
})
Promise.any([p1, p2, p3]).then((res) => {
  console.log('res', res)
}, (err) => {
  console.log('err', err)
})